{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ba522101",
   "metadata": {},
   "source": [
    "# 面向对象常用方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1fd041d1",
   "metadata": {},
   "source": [
    "一、理解\n",
    "\n",
    "1、\\__new__()是在新式类中新出现的方法，它作用在构造方法建造实例之前。\n",
    "\n",
    "　　即可以这样理解：Python中存在于类中的构造方法\\__init__（）负责将类实例化，而在\\__init__（）执行之前，\\__new__（）负责制造这样的一个实例对象，以便\\__init__（）去让该实例对象更加的丰富（为其添加属性等）。\n",
    "\n",
    "　　同时：\\__new__() 方法还决定是否要使用该\\__init__() 方法，因为\\__new__()可以调用其他类的构造方法或者直接返回别的对象来作为本类 的实例。\n",
    "\n",
    "　　2、\\__new__() 方法始终都是类的静态方法，即使没有被加上静态方法装饰器。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e753c237",
   "metadata": {},
   "source": [
    "二、结构\n",
    "　　\n",
    "\n",
    "在Python中，若不重写类中的\\__new__()方法，其默认的结构时这样的："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "39fa004b",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Foo(object):\n",
    "    def __new__(cls,*args,**kwagrs):\n",
    "        return super().__new__(cls,*args,**kwagrs)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "21b730b2",
   "metadata": {},
   "source": [
    "　　1、其第一个参数 cls 是当前正在实例化的类。　\n",
    "\n",
    "　　如果要得到当前类的实例，应当在当前类中的\\__new__()方法语句中调用当前类的父类 的\\__new__()方法。例如，如果当前类是直接继承自object，那当前类的__new__()方法返回的对象应该为："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "89499b87",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
